package com.api.syh56.shengyunhui.mapper;

import com.api.syh56.shengyunhui.entity.User;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface UserMapper extends BaseMapper<User> {


    // 自定义查询方法，添加FOR UPDATE
    @Select("SELECT * FROM user WHERE id = #{id} AND is_deleted = 0 FOR UPDATE")
    User selectByIdForUpdate(@Param("id") Long id);

    // 自定义查询方法，添加FOR UPDATE
    @Select("SELECT * FROM user WHERE user_name = #{userName} AND is_deleted = 0  FOR UPDATE")
    User selectByUserNameForUpdate(@Param("userName") String userName);

    @Select("SELECT * FROM user WHERE company = #{company} AND roles = 1 ORDER BY creation_time DESC")
    List<User> getUser(@Param("company") String company);

    /**
     * 根据openid查询用户
     * @param openid
     * @return
     */
//    @Select("select * from user where openid = #{openid}")
//    User getByOpenid(String openid);


//    @Select("select * from user where id = #{id}")
//    User getById(Long userId);

    /**
     * 根据动态条件统计用户数量
     * @param map
     * @return
     */
//    Integer countByMap(Map map);
}
